import { HttpService } from '@/shared/api/httpService';
import type { Note } from './domain';
import {AppBackendService} from "@/shared/api/appBackendService";

// Define request interfaces
interface CreateNoteRequest {
  content: string;
}

class NotesService extends AppBackendService {


    private urls = {
        notes: '/notes',
    };

    getNotes = async (): Promise<Note[]> => {
        const result = await this.request<Note[]>(this.urls.notes, {}, { method: 'GET' });

        return result;
    };

    createNote = async (data: CreateNoteRequest): Promise<Note> => {
        const result = await this.request<Note>(this.urls.notes, { body: data }, { method: 'POST' });

        return result;
    };

    deleteNote = async (id: number): Promise<void> => {
        // Use POST request with action parameter for deletion
        await this.request<void>(this.urls.notes, {
            body: { action: 'delete', id }
        }, { method: 'POST' });
    };
}

export const notesService = new NotesService();
